﻿using System.Data.Entity;
using System.Linq;
using Mondial2014.Models.Competition;
using Mondial2014.Models.Gambling;

namespace Mondial2014.Models.Context
{
    public class Mondial2014DbContext : DbContext
    {
        public DbSet<Team> Teams { get; set; }

        public DbSet<Group> Groups { get; set; }

        public DbSet<Fixture> Fixtures { get; set; }

        public DbSet<Stage> Stages { get; set; }

        public DbSet<Gambler> Gamblers { get; set; }

        public DbSet<GameGamble> GameGambles { get; set; }
    }

    public static class Mondial2014DbContextExtensions
    {
        public static IQueryable<Fixture> GetFixtures(this Mondial2014DbContext context)
        {
            return context.Fixtures.Include(f => f.Team1).Include(f => f.Team2);
        }

        public static IQueryable<GroupFixture> GetGroupFixtures(this Mondial2014DbContext context)
        {
            return context.Fixtures.OfType<GroupFixture>().Include(f => f.Group).Include(f => f.Team1).Include(f => f.Team2);
        }

        public static IQueryable<GameGamble> GetGameGambles(this Mondial2014DbContext context)
        {
            return context.GameGambles
                .Include(gg => gg.Gambler)
                .Include(gg => gg.Fixture)
                .Include(gg => gg.Fixture.Team1)
                .Include(gg => gg.Fixture.Team2);
        }
    }
}